<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <title>zlals0.f</title>
 <meta name="generator" content="emacs 21.3.1; htmlfontify 0.20">
<style type="text/css"><!-- 
body { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default   { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.default a { background: rgb(255, 255, 255);  color: rgb(0, 0, 0);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.string   { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.string a { color: rgb(188, 143, 143);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
span.comment   { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: none; }
span.comment a { color: rgb(178, 34, 34);  background: rgb(255, 255, 255);  font-style: normal;  font-weight: 500;  font-stretch: normal;  font-family: adobe-courier;  font-size: 11pt;  text-decoration: underline; }
 --></style>

 </head>
  <body>

<pre>
      SUBROUTINE <a name="ZLALS0.1"></a><a href="zlals0.f.html#ZLALS0.1">ZLALS0</a>( ICOMPQ, NL, NR, SQRE, NRHS, B, LDB, BX, LDBX,
     $                   PERM, GIVPTR, GIVCOL, LDGCOL, GIVNUM, LDGNUM,
     $                   POLES, DIFL, DIFR, Z, K, C, S, RWORK, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  -- LAPACK routine (version 3.1) --
</span><span class="comment">*</span><span class="comment">     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
</span><span class="comment">*</span><span class="comment">     November 2006
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Scalar Arguments ..
</span>      INTEGER            GIVPTR, ICOMPQ, INFO, K, LDB, LDBX, LDGCOL,
     $                   LDGNUM, NL, NR, NRHS, SQRE
      DOUBLE PRECISION   C, S
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Array Arguments ..
</span>      INTEGER            GIVCOL( LDGCOL, * ), PERM( * )
      DOUBLE PRECISION   DIFL( * ), DIFR( LDGNUM, * ),
     $                   GIVNUM( LDGNUM, * ), POLES( LDGNUM, * ),
     $                   RWORK( * ), Z( * )
      COMPLEX*16         B( LDB, * ), BX( LDBX, * )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Purpose
</span><span class="comment">*</span><span class="comment">  =======
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  <a name="ZLALS0.25"></a><a href="zlals0.f.html#ZLALS0.1">ZLALS0</a> applies back the multiplying factors of either the left or the
</span><span class="comment">*</span><span class="comment">  right singular vector matrix of a diagonal matrix appended by a row
</span><span class="comment">*</span><span class="comment">  to the right hand side matrix B in solving the least squares problem
</span><span class="comment">*</span><span class="comment">  using the divide-and-conquer SVD approach.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  For the left singular vector matrix, three types of orthogonal
</span><span class="comment">*</span><span class="comment">  matrices are involved:
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  (1L) Givens rotations: the number of such rotations is GIVPTR; the
</span><span class="comment">*</span><span class="comment">       pairs of columns/rows they were applied to are stored in GIVCOL;
</span><span class="comment">*</span><span class="comment">       and the C- and S-values of these rotations are stored in GIVNUM.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  (2L) Permutation. The (NL+1)-st row of B is to be moved to the first
</span><span class="comment">*</span><span class="comment">       row, and for J=2:N, PERM(J)-th row of B is to be moved to the
</span><span class="comment">*</span><span class="comment">       J-th row.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  (3L) The left singular vector matrix of the remaining matrix.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  For the right singular vector matrix, four types of orthogonal
</span><span class="comment">*</span><span class="comment">  matrices are involved:
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  (1R) The right singular vector matrix of the remaining matrix.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  (2R) If SQRE = 1, one extra Givens rotation to generate the right
</span><span class="comment">*</span><span class="comment">       null space.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  (3R) The inverse transformation of (2L).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  (4R) The inverse transformation of (1L).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Arguments
</span><span class="comment">*</span><span class="comment">  =========
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  ICOMPQ (input) INTEGER
</span><span class="comment">*</span><span class="comment">         Specifies whether singular vectors are to be computed in
</span><span class="comment">*</span><span class="comment">         factored form:
</span><span class="comment">*</span><span class="comment">         = 0: Left singular vector matrix.
</span><span class="comment">*</span><span class="comment">         = 1: Right singular vector matrix.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  NL     (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The row dimension of the upper block. NL &gt;= 1.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  NR     (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The row dimension of the lower block. NR &gt;= 1.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  SQRE   (input) INTEGER
</span><span class="comment">*</span><span class="comment">         = 0: the lower block is an NR-by-NR square matrix.
</span><span class="comment">*</span><span class="comment">         = 1: the lower block is an NR-by-(NR+1) rectangular matrix.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">         The bidiagonal matrix has row dimension N = NL + NR + 1,
</span><span class="comment">*</span><span class="comment">         and column dimension M = N + SQRE.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  NRHS   (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The number of columns of B and BX. NRHS must be at least 1.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  B      (input/output) COMPLEX*16 array, dimension ( LDB, NRHS )
</span><span class="comment">*</span><span class="comment">         On input, B contains the right hand sides of the least
</span><span class="comment">*</span><span class="comment">         squares problem in rows 1 through M. On output, B contains
</span><span class="comment">*</span><span class="comment">         the solution X in rows 1 through N.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDB    (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The leading dimension of B. LDB must be at least
</span><span class="comment">*</span><span class="comment">         max(1,MAX( M, N ) ).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  BX     (workspace) COMPLEX*16 array, dimension ( LDBX, NRHS )
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDBX   (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The leading dimension of BX.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  PERM   (input) INTEGER array, dimension ( N )
</span><span class="comment">*</span><span class="comment">         The permutations (from deflation and sorting) applied
</span><span class="comment">*</span><span class="comment">         to the two blocks.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  GIVPTR (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The number of Givens rotations which took place in this
</span><span class="comment">*</span><span class="comment">         subproblem.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  GIVCOL (input) INTEGER array, dimension ( LDGCOL, 2 )
</span><span class="comment">*</span><span class="comment">         Each pair of numbers indicates a pair of rows/columns
</span><span class="comment">*</span><span class="comment">         involved in a Givens rotation.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDGCOL (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The leading dimension of GIVCOL, must be at least N.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  GIVNUM (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 )
</span><span class="comment">*</span><span class="comment">         Each number indicates the C or S value used in the
</span><span class="comment">*</span><span class="comment">         corresponding Givens rotation.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  LDGNUM (input) INTEGER
</span><span class="comment">*</span><span class="comment">         The leading dimension of arrays DIFR, POLES and
</span><span class="comment">*</span><span class="comment">         GIVNUM, must be at least K.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  POLES  (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 )
</span><span class="comment">*</span><span class="comment">         On entry, POLES(1:K, 1) contains the new singular
</span><span class="comment">*</span><span class="comment">         values obtained from solving the secular equation, and
</span><span class="comment">*</span><span class="comment">         POLES(1:K, 2) is an array containing the poles in the secular
</span><span class="comment">*</span><span class="comment">         equation.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  DIFL   (input) DOUBLE PRECISION array, dimension ( K ).
</span><span class="comment">*</span><span class="comment">         On entry, DIFL(I) is the distance between I-th updated
</span><span class="comment">*</span><span class="comment">         (undeflated) singular value and the I-th (undeflated) old
</span><span class="comment">*</span><span class="comment">         singular value.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  DIFR   (input) DOUBLE PRECISION array, dimension ( LDGNUM, 2 ).
</span><span class="comment">*</span><span class="comment">         On entry, DIFR(I, 1) contains the distances between I-th
</span><span class="comment">*</span><span class="comment">         updated (undeflated) singular value and the I+1-th
</span><span class="comment">*</span><span class="comment">         (undeflated) old singular value. And DIFR(I, 2) is the
</span><span class="comment">*</span><span class="comment">         normalizing factor for the I-th right singular vector.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Z      (input) DOUBLE PRECISION array, dimension ( K )
</span><span class="comment">*</span><span class="comment">         Contain the components of the deflation-adjusted updating row
</span><span class="comment">*</span><span class="comment">         vector.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  K      (input) INTEGER
</span><span class="comment">*</span><span class="comment">         Contains the dimension of the non-deflated matrix,
</span><span class="comment">*</span><span class="comment">         This is the order of the related secular equation. 1 &lt;= K &lt;=N.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  C      (input) DOUBLE PRECISION
</span><span class="comment">*</span><span class="comment">         C contains garbage if SQRE =0 and the C-value of a Givens
</span><span class="comment">*</span><span class="comment">         rotation related to the right null space if SQRE = 1.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  S      (input) DOUBLE PRECISION
</span><span class="comment">*</span><span class="comment">         S contains garbage if SQRE =0 and the S-value of a Givens
</span><span class="comment">*</span><span class="comment">         rotation related to the right null space if SQRE = 1.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  RWORK  (workspace) DOUBLE PRECISION array, dimension
</span><span class="comment">*</span><span class="comment">         ( K*(1+NRHS) + 2*NRHS )
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  INFO   (output) INTEGER
</span><span class="comment">*</span><span class="comment">          = 0:  successful exit.
</span><span class="comment">*</span><span class="comment">          &lt; 0:  if INFO = -i, the i-th argument had an illegal value.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Further Details
</span><span class="comment">*</span><span class="comment">  ===============
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  Based on contributions by
</span><span class="comment">*</span><span class="comment">     Ming Gu and Ren-Cang Li, Computer Science Division, University of
</span><span class="comment">*</span><span class="comment">       California at Berkeley, USA
</span><span class="comment">*</span><span class="comment">     Osni Marques, LBNL/NERSC, USA
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">  =====================================================================
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     .. Parameters ..
</span>      DOUBLE PRECISION   ONE, ZERO, NEGONE
      PARAMETER          ( ONE = 1.0D0, ZERO = 0.0D0, NEGONE = -1.0D0 )
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Local Scalars ..
</span>      INTEGER            I, J, JCOL, JROW, M, N, NLP1
      DOUBLE PRECISION   DIFLJ, DIFRJ, DJ, DSIGJ, DSIGJP, TEMP
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Subroutines ..
</span>      EXTERNAL           DGEMV, <a name="XERBLA.176"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>, ZCOPY, <a name="ZDROT.176"></a><a href="zdrot.f.html#ZDROT.1">ZDROT</a>, ZDSCAL, <a name="ZLACPY.176"></a><a href="zlacpy.f.html#ZLACPY.1">ZLACPY</a>,
     $                   <a name="ZLASCL.177"></a><a href="zlascl.f.html#ZLASCL.1">ZLASCL</a>
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. External Functions ..
</span>      DOUBLE PRECISION   <a name="DLAMC3.180"></a><a href="dlamch.f.html#DLAMC3.574">DLAMC3</a>, DNRM2
      EXTERNAL           <a name="DLAMC3.181"></a><a href="dlamch.f.html#DLAMC3.574">DLAMC3</a>, DNRM2
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Intrinsic Functions ..
</span>      INTRINSIC          DBLE, DCMPLX, DIMAG, MAX
<span class="comment">*</span><span class="comment">     ..
</span><span class="comment">*</span><span class="comment">     .. Executable Statements ..
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     Test the input parameters.
</span><span class="comment">*</span><span class="comment">
</span>      INFO = 0
<span class="comment">*</span><span class="comment">
</span>      IF( ( ICOMPQ.LT.0 ) .OR. ( ICOMPQ.GT.1 ) ) THEN
         INFO = -1
      ELSE IF( NL.LT.1 ) THEN
         INFO = -2
      ELSE IF( NR.LT.1 ) THEN
         INFO = -3
      ELSE IF( ( SQRE.LT.0 ) .OR. ( SQRE.GT.1 ) ) THEN
         INFO = -4
      END IF
<span class="comment">*</span><span class="comment">
</span>      N = NL + NR + 1
<span class="comment">*</span><span class="comment">
</span>      IF( NRHS.LT.1 ) THEN
         INFO = -5
      ELSE IF( LDB.LT.N ) THEN
         INFO = -7
      ELSE IF( LDBX.LT.N ) THEN
         INFO = -9
      ELSE IF( GIVPTR.LT.0 ) THEN
         INFO = -11
      ELSE IF( LDGCOL.LT.N ) THEN
         INFO = -13
      ELSE IF( LDGNUM.LT.N ) THEN
         INFO = -15
      ELSE IF( K.LT.1 ) THEN
         INFO = -20
      END IF
      IF( INFO.NE.0 ) THEN
         CALL <a name="XERBLA.220"></a><a href="xerbla.f.html#XERBLA.1">XERBLA</a>( <span class="string">'<a name="ZLALS0.220"></a><a href="zlals0.f.html#ZLALS0.1">ZLALS0</a>'</span>, -INFO )
         RETURN
      END IF
<span class="comment">*</span><span class="comment">
</span>      M = N + SQRE
      NLP1 = NL + 1
<span class="comment">*</span><span class="comment">
</span>      IF( ICOMPQ.EQ.0 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Apply back orthogonal transformations from the left.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Step (1L): apply back the Givens rotations performed.
</span><span class="comment">*</span><span class="comment">
</span>         DO 10 I = 1, GIVPTR
            CALL <a name="ZDROT.234"></a><a href="zdrot.f.html#ZDROT.1">ZDROT</a>( NRHS, B( GIVCOL( I, 2 ), 1 ), LDB,
     $                  B( GIVCOL( I, 1 ), 1 ), LDB, GIVNUM( I, 2 ),
     $                  GIVNUM( I, 1 ) )
   10    CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Step (2L): permute rows of B.
</span><span class="comment">*</span><span class="comment">
</span>         CALL ZCOPY( NRHS, B( NLP1, 1 ), LDB, BX( 1, 1 ), LDBX )
         DO 20 I = 2, N
            CALL ZCOPY( NRHS, B( PERM( I ), 1 ), LDB, BX( I, 1 ), LDBX )
   20    CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Step (3L): apply the inverse of the left singular vector
</span><span class="comment">*</span><span class="comment">        matrix to BX.
</span><span class="comment">*</span><span class="comment">
</span>         IF( K.EQ.1 ) THEN
            CALL ZCOPY( NRHS, BX, LDBX, B, LDB )
            IF( Z( 1 ).LT.ZERO ) THEN
               CALL ZDSCAL( NRHS, NEGONE, B, LDB )
            END IF
         ELSE
            DO 100 J = 1, K
               DIFLJ = DIFL( J )
               DJ = POLES( J, 1 )
               DSIGJ = -POLES( J, 2 )
               IF( J.LT.K ) THEN
                  DIFRJ = -DIFR( J, 1 )
                  DSIGJP = -POLES( J+1, 2 )
               END IF
               IF( ( Z( J ).EQ.ZERO ) .OR. ( POLES( J, 2 ).EQ.ZERO ) )
     $              THEN
                  RWORK( J ) = ZERO
               ELSE
                  RWORK( J ) = -POLES( J, 2 )*Z( J ) / DIFLJ /
     $                         ( POLES( J, 2 )+DJ )
               END IF
               DO 30 I = 1, J - 1
                  IF( ( Z( I ).EQ.ZERO ) .OR.
     $                ( POLES( I, 2 ).EQ.ZERO ) ) THEN
                     RWORK( I ) = ZERO
                  ELSE
                     RWORK( I ) = POLES( I, 2 )*Z( I ) /
     $                            ( <a name="DLAMC3.276"></a><a href="dlamch.f.html#DLAMC3.574">DLAMC3</a>( POLES( I, 2 ), DSIGJ )-
     $                            DIFLJ ) / ( POLES( I, 2 )+DJ )
                  END IF
   30          CONTINUE
               DO 40 I = J + 1, K
                  IF( ( Z( I ).EQ.ZERO ) .OR.
     $                ( POLES( I, 2 ).EQ.ZERO ) ) THEN
                     RWORK( I ) = ZERO
                  ELSE
                     RWORK( I ) = POLES( I, 2 )*Z( I ) /
     $                            ( <a name="DLAMC3.286"></a><a href="dlamch.f.html#DLAMC3.574">DLAMC3</a>( POLES( I, 2 ), DSIGJP )+
     $                            DIFRJ ) / ( POLES( I, 2 )+DJ )
                  END IF
   40          CONTINUE
               RWORK( 1 ) = NEGONE
               TEMP = DNRM2( K, RWORK, 1 )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Since B and BX are complex, the following call to DGEMV
</span><span class="comment">*</span><span class="comment">              is performed in two steps (real and imaginary parts).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              CALL DGEMV( 'T', K, NRHS, ONE, BX, LDBX, WORK, 1, ZERO,
</span><span class="comment">*</span><span class="comment">    $                     B( J, 1 ), LDB )
</span><span class="comment">*</span><span class="comment">
</span>               I = K + NRHS*2
               DO 60 JCOL = 1, NRHS
                  DO 50 JROW = 1, K
                     I = I + 1
                     RWORK( I ) = DBLE( BX( JROW, JCOL ) )
   50             CONTINUE
   60          CONTINUE
               CALL DGEMV( <span class="string">'T'</span>, K, NRHS, ONE, RWORK( 1+K+NRHS*2 ), K,
     $                     RWORK( 1 ), 1, ZERO, RWORK( 1+K ), 1 )
               I = K + NRHS*2
               DO 80 JCOL = 1, NRHS
                  DO 70 JROW = 1, K
                     I = I + 1
                     RWORK( I ) = DIMAG( BX( JROW, JCOL ) )
   70             CONTINUE
   80          CONTINUE
               CALL DGEMV( <span class="string">'T'</span>, K, NRHS, ONE, RWORK( 1+K+NRHS*2 ), K,
     $                     RWORK( 1 ), 1, ZERO, RWORK( 1+K+NRHS ), 1 )
               DO 90 JCOL = 1, NRHS
                  B( J, JCOL ) = DCMPLX( RWORK( JCOL+K ),
     $                           RWORK( JCOL+K+NRHS ) )
   90          CONTINUE
               CALL <a name="ZLASCL.321"></a><a href="zlascl.f.html#ZLASCL.1">ZLASCL</a>( <span class="string">'G'</span>, 0, 0, TEMP, ONE, 1, NRHS, B( J, 1 ),
     $                      LDB, INFO )
  100       CONTINUE
         END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Move the deflated rows of BX to B also.
</span><span class="comment">*</span><span class="comment">
</span>         IF( K.LT.MAX( M, N ) )
     $      CALL <a name="ZLACPY.329"></a><a href="zlacpy.f.html#ZLACPY.1">ZLACPY</a>( <span class="string">'A'</span>, N-K, NRHS, BX( K+1, 1 ), LDBX,
     $                   B( K+1, 1 ), LDB )
      ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Apply back the right orthogonal transformations.
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Step (1R): apply back the new right singular vector matrix
</span><span class="comment">*</span><span class="comment">        to B.
</span><span class="comment">*</span><span class="comment">
</span>         IF( K.EQ.1 ) THEN
            CALL ZCOPY( NRHS, B, LDB, BX, LDBX )
         ELSE
            DO 180 J = 1, K
               DSIGJ = POLES( J, 2 )
               IF( Z( J ).EQ.ZERO ) THEN
                  RWORK( J ) = ZERO
               ELSE
                  RWORK( J ) = -Z( J ) / DIFL( J ) /
     $                         ( DSIGJ+POLES( J, 1 ) ) / DIFR( J, 2 )
               END IF
               DO 110 I = 1, J - 1
                  IF( Z( J ).EQ.ZERO ) THEN
                     RWORK( I ) = ZERO
                  ELSE
                     RWORK( I ) = Z( J ) / ( <a name="DLAMC3.353"></a><a href="dlamch.f.html#DLAMC3.574">DLAMC3</a>( DSIGJ, -POLES( I+1,
     $                            2 ) )-DIFR( I, 1 ) ) /
     $                            ( DSIGJ+POLES( I, 1 ) ) / DIFR( I, 2 )
                  END IF
  110          CONTINUE
               DO 120 I = J + 1, K
                  IF( Z( J ).EQ.ZERO ) THEN
                     RWORK( I ) = ZERO
                  ELSE
                     RWORK( I ) = Z( J ) / ( <a name="DLAMC3.362"></a><a href="dlamch.f.html#DLAMC3.574">DLAMC3</a>( DSIGJ, -POLES( I,
     $                            2 ) )-DIFL( I ) ) /
     $                            ( DSIGJ+POLES( I, 1 ) ) / DIFR( I, 2 )
                  END IF
  120          CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              Since B and BX are complex, the following call to DGEMV
</span><span class="comment">*</span><span class="comment">              is performed in two steps (real and imaginary parts).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">              CALL DGEMV( 'T', K, NRHS, ONE, B, LDB, WORK, 1, ZERO,
</span><span class="comment">*</span><span class="comment">    $                     BX( J, 1 ), LDBX )
</span><span class="comment">*</span><span class="comment">
</span>               I = K + NRHS*2
               DO 140 JCOL = 1, NRHS
                  DO 130 JROW = 1, K
                     I = I + 1
                     RWORK( I ) = DBLE( B( JROW, JCOL ) )
  130             CONTINUE
  140          CONTINUE
               CALL DGEMV( <span class="string">'T'</span>, K, NRHS, ONE, RWORK( 1+K+NRHS*2 ), K,
     $                     RWORK( 1 ), 1, ZERO, RWORK( 1+K ), 1 )
               I = K + NRHS*2
               DO 160 JCOL = 1, NRHS
                  DO 150 JROW = 1, K
                     I = I + 1
                     RWORK( I ) = DIMAG( B( JROW, JCOL ) )
  150             CONTINUE
  160          CONTINUE
               CALL DGEMV( <span class="string">'T'</span>, K, NRHS, ONE, RWORK( 1+K+NRHS*2 ), K,
     $                     RWORK( 1 ), 1, ZERO, RWORK( 1+K+NRHS ), 1 )
               DO 170 JCOL = 1, NRHS
                  BX( J, JCOL ) = DCMPLX( RWORK( JCOL+K ),
     $                            RWORK( JCOL+K+NRHS ) )
  170          CONTINUE
  180       CONTINUE
         END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Step (2R): if SQRE = 1, apply back the rotation that is
</span><span class="comment">*</span><span class="comment">        related to the right null space of the subproblem.
</span><span class="comment">*</span><span class="comment">
</span>         IF( SQRE.EQ.1 ) THEN
            CALL ZCOPY( NRHS, B( M, 1 ), LDB, BX( M, 1 ), LDBX )
            CALL <a name="ZDROT.404"></a><a href="zdrot.f.html#ZDROT.1">ZDROT</a>( NRHS, BX( 1, 1 ), LDBX, BX( M, 1 ), LDBX, C, S )
         END IF
         IF( K.LT.MAX( M, N ) )
     $      CALL <a name="ZLACPY.407"></a><a href="zlacpy.f.html#ZLACPY.1">ZLACPY</a>( <span class="string">'A'</span>, N-K, NRHS, B( K+1, 1 ), LDB, BX( K+1, 1 ),
     $                   LDBX )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Step (3R): permute rows of B.
</span><span class="comment">*</span><span class="comment">
</span>         CALL ZCOPY( NRHS, BX( 1, 1 ), LDBX, B( NLP1, 1 ), LDB )
         IF( SQRE.EQ.1 ) THEN
            CALL ZCOPY( NRHS, BX( M, 1 ), LDBX, B( M, 1 ), LDB )
         END IF
         DO 190 I = 2, N
            CALL ZCOPY( NRHS, BX( I, 1 ), LDBX, B( PERM( I ), 1 ), LDB )
  190    CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">        Step (4R): apply back the Givens rotations performed.
</span><span class="comment">*</span><span class="comment">
</span>         DO 200 I = GIVPTR, 1, -1
            CALL <a name="ZDROT.423"></a><a href="zdrot.f.html#ZDROT.1">ZDROT</a>( NRHS, B( GIVCOL( I, 2 ), 1 ), LDB,
     $                  B( GIVCOL( I, 1 ), 1 ), LDB, GIVNUM( I, 2 ),
     $                  -GIVNUM( I, 1 ) )
  200    CONTINUE
      END IF
<span class="comment">*</span><span class="comment">
</span>      RETURN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment">     End of <a name="ZLALS0.431"></a><a href="zlals0.f.html#ZLALS0.1">ZLALS0</a>
</span><span class="comment">*</span><span class="comment">
</span>      END

</pre>

 </body>
</html>
